<?php
/**
 * 个人账户控制器
 * User: 苏近之
 * Date: 2019-03-23
 * Time: 16:54
 */

namespace app\user\controller;

use app\common\base\ApiController;
use app\common\exception\RequestParamsVerifyFailed;
use app\user\service\PersonAccountService;
use app\user\validator\PersonAccountRegisterWithPhone;
use app\user\validator\PersonAccountSubmitUserLoginInfo;
use think\facade\Request;

class PersonAccount extends ApiController
{

    /**
     * 提交手机号注册信息
     * @throws
     */
    public function registerWithPhone()
    {
        $requestParams = Request::post();
        $validator = new PersonAccountRegisterWithPhone();
        if(!$validator->check($requestParams)){
            throw new RequestParamsVerifyFailed($validator->getError());
        }
        $token = PersonAccountService::verifyPhoneAndCode($requestParams['phone'], $requestParams['verifyCode']);

        return $this->responseWithJson($token);
    }

    /**
     * 提交用户注册信息
     * @return \think\response\Json
     * @throws
     */
    public function submitUserLoginInfo()
    {
        $requestParams = Request::post();
        $validator = new PersonAccountSubmitUserLoginInfo();
        if(!$validator->check($requestParams)){
            throw new RequestParamsVerifyFailed($validator->getError());
        }
        PersonAccountService::submitRegisterInfo($requestParams);

        return $this->responseWithJson();
    }

}